home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
asm_n_z.zip
/
TOUCHE.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-06-01
|
19KB
|
653 lines
page 58,132
title TOUCHE -- A File Date Maintenance Utility
name TOUCHE
comment *
This program will change the date/time stamp of all files on its
command line to the current date and time.
See TOUCHE.DOC for instructions on how to use this program.
Copyright (c) 1986 Raymond Moon ALL RIGHTS RESERVED
*
;----------------------------
; Define the various macros used in this program.
@CLOSE macro FH ;; DOS 2.0+ Close File/Device Macro
mov bx,FH ; Load File Handle into BX
mov ah,3eh ; Request DOS close File Handle
int 21h ; Call PC-DOS
endm
@ENTRY macro ;; Standard Procedure Entry Logic
push bp ; Save BP
mov bp,sp ; Establish stack addressability
endm
@EXIT macro RTNCODE ;; Terminate program with return code
mov ax,4c&RTNCODE&h ; Request term with return code
int 21h ; Call PC-DOS
endm
@GETDATE macro ;; Get Current Date Macro
mov ah,2ah ; Request DOS get current date
int 21h ; Call PC-DOS
endm
@GETTIME macro ;; Get Current Time Macro
mov ah,2ch ; Request DOS get current time
int 21h ; Call PC-DOS
endm
@OPEN macro FILESPEC,MODE ;; DOS 2.0+ Open File Macro
lea dx,FILESPEC ; Load addr of FILESPEC in DX
mov ax,3D0&MODE&h ; Request DOS open file with mode
int 21h ; Call PC-DOS
endm
@WRITE macro STRING,FH ;; DOS 2.0+ Write to File Macro
lea dx,STRING ; Load String addr in DX
mov cx,STRING&_LEN ; Load String Length in CX
mov bx,FH ; Load File Handle in BX
mov ah,40h ; Request DOS write to file/device
int 21h ; Call PC-DOS
endm
;----------------------------
; Define various equates used in this program
STDOUT equ 1
STDERR equ 2
TAB equ 9
BLNK equ 20h
LF equ 0ah
CR equ 0dh
;----------------------------
; Define the group and segments so that all will reside in one 64K
; physical segment.
GRP group CSEG,DTA,DSEGB,DSEGA ; All segments in same segment
assume cs:GRP,ds:GRP,es:GRP,ss:GRP
DSEGB segment byte public 'STRING'
public LOGO, DOS_ERR, NOT_FOUND, TOUCHED, PROPER_USE, CANT
LOGO db 'TOUCHE -- A File Date Maintenance Utility V1.00',CR,LF
db 'Copyright 1986 - MoonWare',CR,LF,LF
LOGO_LEN equ $ - LOGO
DOS_ERR db CR,LF,LF,'TOUCHE: Need DOS 2.0+'
NOT_FOUND db ' -- Not Found',CR,LF
NOT_FOUND_LEN equ $ - NOT_FOUND
TOUCHED db ' -- Touched',CR,LF
TOUCHED_LEN equ $ - TOUCHED
CANT db ' -- Cannot Touch',CR,LF
CANT_LEN equ $ - CANT
PROPER_USE db CR,LF,'TOUCHE: Nothing to do.',CR,LF,LF,'Use:',CR,LF,LF,TAB
db 'touche file1.ext file2.ext . . . fileN.ext',CR,LF,LF,TAB
db 'Drive, Path, and Wildcards allowed in file names.',CR,LF,LF
PROPER_USE_LEN equ $ - PROPER_USE
db '***** 30 May 1986 -- Raymond Moon *****'
DSEGB ends
DSEGA segment byte public 'DATA'
public pDOS_ERR
pDOS_ERR dw offset GRP:DOS_ERR
DSEGA ends
;----------------------------
; Use 'Segment At' to create variable to access the information
; contained in the DTA after First Find/Next Find DOS Function
; call is used.
DTA segment at 00h
public FILENAME
org 80h
RESERVED_DOS db 21 dup (?)
DTA_ATTRIB db ?
DTA_TIME dw ?
DTA_DATE dw ?
DTA_SIZE_LO dw ?
DTA_SIZE_HI dw ?
FILENAME db 13 dup (?)
DTA ends
;----------------------------
; Define structure to address argc and *argv[].
STACK_PARMS struc
dw ?,? ; Saved BP & Return Address
ARGC dw ? ; Count of command line arguments
ARGV dw ? ; Address to command line arguments
STACK_PARMS ends
CSEG segment para public 'CODE'
;-----------------------------
; Define all procedures as public for debugging
public MAIN, TOUCH_FILES, NOTHING_TO_DO, ISDOS2, FPUTS, STRCPY, STRLEN
;-----------------------------
; Define Command Line arguments located in the PSP
org 80h
PARM_LEN db ?
PARMS db 127 dup(?)
;-----------------------------
; MAIN procedure parses the Command Line
org 100h ; .COM file format
MAIN proc far
push pDOS_ERR ; Pass addr of DOS_ERR
call ISDOS2 ; Check to see if DOS is 2.0+
add sp,2 ; Reset SP
cmp PARM_LEN,0 ; Are there any Command Line arguments
jne MN1 ; Yes, process them
call NOTHING_TO_DO ; No, go to Nothing_to_do
MN1: xor cx,cx ; Null CX
push cx ; This ensures last *argv ends in NUL
mov cl,PARM_LEN ; Get # of bytes in Command Line
inc cl ; Increment CL to ensure round up
and cx,0feh ; Force an even count
mov ax,sp ; Get SP
mov bp,sp ; Set BP to last byte of Cmd Ln
sub ax,cx ; Subtract PARM_LEN
mov sp,ax ; Reset SP, room on Stack
lea si,PARMS ; Load source addr in SI
mov di,sp ; Load destin addr in DI
cld ; Ensure Direction Flag is up
rep movsb ; Move Command Line onto the Stack
;-----------------------------
; Convert all blanks in the Command Line to Nul
mov bx,bp ; BX points to last byte of Cmd Ln
MN2: mov al,[bx] ; Get byte
cmp al,BLNK ; Is it a blank?
ja MN3 ; No, go set up to get another
xor al,al ; Nul AX
mov [bx],al ; Store Nul in [BX]
MN3: dec bx ; BX point to next byte
cmp bx,sp ; Are we through yet?
jnb MN2 ; No, go one mo' 'gin
;-----------------------------
; Build *argv[]. argc kept in CX. DX used as IN_WORD flag
xor cx,cx ; Set CX (argc) to 0
xor dx,dx ; Set DX to NOT_INWORD
mov bx,bp ; BX point to last byte
mov bp,sp ; BP now points to Top of Stack
MN4: mov al,[bx] ; Get byte
cmp al,0 ; Is it Nul?
jne MN5 ; No, it is a char
cmp dx,0 ; Was the last byte not a char?
je MN6 ; Yes, go on with the processing
xor dx,dx ; No, it was a char. Clear INWORD.
inc cx ; Increment argc
inc bx ; BX points to Cmd Ln arg
push bx ; Push addr onto stack
dec bx ; Reset BX
jmp short MN6 ; Go set up for another byte
MN5: inc dx ; Set DX to INWORD
MN6: dec bx ; BX point to next byte
cmp bx,bp ; Are we at the 1st byte yet?
jnb MN4 ; No, go process another
;-----------------------------
; Set up for and call TOUCH_FILES
push cx ; Push ARGC onto stack
call TOUCH_FILES ; Process files
MAIN endp
;----------------------------
; This procedure prints the string PROPER_USE then terminates the
; program.
NOTHING_TO_DO proc near
@WRITE PROPER_USE,STDERR ; Tell the user how to use TOUCH
@EXIT 01 ; Exit with return code of 1
NOTHING_TO_DO endp
;----------------------------
; Process each filename one at a time.
TOUCH_FILES proc near
@ENTRY ; Std Entry Logic
sub sp,75 ; Make room for automatic variables
TF_BASE equ [bp - 75] ; Automatic variable addressing base
TF_AUTO struc ; Automatic variable structure
DATE dw ?
TIME dw ?
COUNT dw ?
LENGTH dw ?
FILE_HANDLE dw ?
PATH_END dw ?
FILESPEC db 63 dup (?)
TF_AUTO ends
;----------------------------
; Display logo
@WRITE LOGO,STDOUT
;----------------------------
; Get the time and date. Convert these into DOS file date/time stamp
; format.
@GETDATE ; Get the DOS date
xor ax,ax ; Nul AX
sub cx,1980 ; Convert #years into DOS file format
xchg ch,cl ; Move year into CH
shl ch,1 ; Convert year into DOS file format
or ah,ch ; Move it into AX
xor bx,bx ; Nul BX
mov bh,dh ; Month into BX
shr bx,1
shr bx,1
shr bx,1 ; Convert month into DOS file format
or ax,bx ; Move it into AX
or al,dl ; Move seconds into AX
mov TF_BASE.DATE,ax ; Save it
;----------------------------
; Get the time and convert it.
@GETTIME ; Get the DOS time
xor ax,ax ; Nul AX
xor bx,bx ; Nul BX
shl ch,1
shl ch,1
shl ch,1 ; Convert hour into DOS file format
or ah,ch ; Move it into AX
mov bh,cl ; Move minutes into BH
shr bx,1
shr bx,1
shr bx,1 ; Convert minutes into DOS file format
or ax,bx ; Move it into AX
or al,dh ; Move seconds into AX
mov TF_BASE.TIME,ax ; Save it
;----------------------------
; Set Count to zero.
xor ax,ax ; Nul AX
mov TF_BASE.COUNT,ax ; Set count to zero
;----------------------------
; Process next file in command line. Start by stripping off any drive
; and path and save it in filespec. Start b